<?php
include_once 'basepath.php';
//print_r($idbus."--idtour".$idtour);
//print_r($addbookingID);
//print_r($forfait);
//print_r($infotour);


?>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">

<link rel="stylesheet" href="<?php echo $bpath;?>/css/reset.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/text.css" />
<link rel="stylesheet" href="<?php echo $bpath;?>/css/960_24_col.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/jquery-ui-1.8.21.custom.css" />
  <link rel="stylesheet" href="<?php echo $bpath;?>/css/faary.css" type="text/css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/style.css" />
 <link rel="stylesheet" href="<?php echo $bpath;?>/css/apprise.min.css" type="text/css">

 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-1.7.2.min.js"></script>
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery-ui-1.8.21.custom.min.js"></script>
<script type="text/javascript" src="<?php echo $bpath;?>/js/scripts.js"></script>
 <script type="text/javascript" src="<?php echo $bpath;?>/js/jquery.validate.js"></script>
 	<script type="text/javascript" src="<?php echo $bpath;?>/js/apprise-1.5.min.js"></script>"
 <script type="text/javascript">
	$(function(){
		//change price by total people
		
		jQuery.validator.addMethod("telphone", function(value, element) { 
			  return this.optional(element) || /^\d{3}\-\d{7}$/.test(value); 
			}, "Please specify the correct domain");
		
		$(".forminscr").validate({
				submitHandler: function(form){ 
					telnumber=$("input.nbtel").val();
					getidclient=$("input.get_idclient").val();
					if(getidclient==0){
					 $.ajax({
				            url: "index.php?add/seachclientbytel/"+telnumber,
				            type:'POST',
				            dataType: 'json',
				            success: function(output_string){
					            if(output_string.etat=="yes"){
									var str_info="This telephone number exit , click check for get more information"

				                 	apprise(str_info, {'verify':false}, function(r)
											 {
												

											 });//alert yes

					           	 		}else{
					           	 		var placeask=$("#numberpeople").val();
										var idbus=$("input[name=idbus]").val();
										if(chkplace(idbus,placeask)=="yes")	
										{
											form.submit() 
										}else(alert("This bus has not Enough seat for booking"));	
					           	 		
					           	 	}//etat is yess or ono
				                } // End of success function of ajax form
				            }); // End of ajax call 
					}else{
						var placeask=$("#numberpeople").val();
						var idbus=$("input[name=idbus]").val();
						if(chkplace(idbus,placeask)=="yes")	
						{
							form.submit() 
						}else(alert("This bus has not Enough seat for booking"))
					}

					},
				 onfocusout:  function(element) { $(element).valid(); },

				rules: {
					
					FirstName: {
						required: true,
						minlength: 3
					},
				
					
					LastName: {
						required: true,
						minlength: 3
		     		 },
		   			
		     		Telephone: {
		     		 required: true,
		     		 telphone:true
		     		 			},
		     		 Email : {
		     		 required: true,
		     		email:true
		   			},

		     		Language: {
		     			 required: true
		     				},  			
		     		SalsePrice:{
		     			required: true
			     		}
				},
				
				messages: {
					FirstName: "Enter First Name(at least 3 caracter )",
					LastName: "Enter First Name(at least 3 caracter )",
					Telephone:"Enter Number telephone(format:xxx-xxxxxxx)",
					Email:"Enter Email"
					}
				
		});

//check client exit in table clients?
		$("input.tel").click(function(){
			telnumber=$("input.nbtel").val();
			$("input.nbtel").removeAttr("disabled");
			
		 $.ajax({
	            url: "index.php?add/seachclientbytel/"+telnumber,
	            type:'POST',
	            dataType: 'json',
	            success: function(output_string){
		            if(output_string.etat=="yes"){
						var str_info="<h3 align='center'>Client's Information found</h3><table width='500' border='1'><tr><td>Fisrt Name:</td><td>"+output_string[0].firstname+"</td><td>Last Name:</td><td>"+output_string[0].lastname+"</td></tr>	<tr><td>Tel:</td><td>"+output_string[0].telphone+"</td><td>Email:</td><td>"+output_string[0].email+"</td>	</tr></table><h4 align='center'>you want use this infomation?</h4>"

	                 	apprise(str_info, {'verify':true}, function(r)
								 {
									 if(r){
											$("input.get_idclient").val(output_string[0].idclients);
											$("input#FirstName").val(output_string[0].firstname);
											$("input#LastName").val(output_string[0].lastname);
											$("input#Email").val(output_string[0].email);
											$("input#address").val(output_string[0].address);
											//alert("yes")
											$("input.nbtel").attr("readonly","");
										 }else{

											 $("input.nbtel").val("");
											 $("input.get_idclient").val(0);
											 $("input#FirstName").val("");
											 $("input#LastName").val("");
											 $("input#Email").val("");
											 $("input#address").val("");
											 $("input.nbtel").removeAttr("readonly")

											 }

								 });//alert yes

		           	 		}else
			           	 		{
									alert("This Telephone Number isn't found !");
			           	 		}//etat is yess or no
	                } // End of success function of ajax form
	            }); // End of ajax call 
	 			
			});//click 


		function chkplace(idbus,placeask)
			{
				var returnvalue="no";
				$.ajax({
	            url: "index.php?liste/ckplacevalid/"+idbus,
	            type:'POST',
	            dataType: 'json',
	            async:false,
	            success: function(output_string){
					
	            	var validplace=output_string;
	            	var ecart=validplace-placeask;
	            	if(ecart>=0)
	            	{returnvalue="yes"}else{returnvalue="no"};
					
	            	}
					});//ajax
				return returnvalue;
			}

//__________forfait
var forfait=Array();

<?php if(count($forfait)>0){
		foreach ($forfait as $ff)
		{?>
		var info=new Object();
		info.ttle="<?php echo $ff["title"]; ?>"
		info.ap="<?php echo $ff["priceadult"]; ?>"
		info.cp="<?php echo $ff["pricechild"];?>"
		forfait[<?php echo $ff["chambretype"];?>]=info;
<?php } }?>

//_______ change nb calcule prix 
console.log(forfait);		

var totalpricefinal=0;
var adulttotalfinal=0;
var childtotoalfinal=0;


	
//###########################################################################################	

<?php if($infotour[0]["forfaittype"]==0){?>
/*
 *  loader intial
 */
//----------- adult----------------------
	 var nb=$("#numberpeople").val();
	 $("#chambre").val(nb);
	 var unitprix=forfait[0]
	 adulttotalfinal=nb*unitprix.ap;
	totalpricefinal=adulttotalfinal+childtotoalfinal;
	//alert(total);
	$("span.forfait").html("forfait: "+unitprix.ttle+"-")
	$("span.priceadult").html("Adult: "+unitprix.ap+",Total:"+adulttotalfinal.toFixed(2));
	$("#SalsePrice").val(totalpricefinal.toFixed(2));
	$("#orginalprice").val(totalpricefinal.toFixed(2))
	
//--------------------- child---------------
				var nb=$("#nbchild").val();
				var unitprix=forfait[0]
				 childtotoalfinal=nb*unitprix.cp;
				totalpricefinal=adulttotalfinal+childtotoalfinal;
				//alert(total);
				$("span.forfait").html("forfait: "+unitprix.ttle+"-")
				$("span.pricechild").html("Child: "+unitprix.cp+",Total:"+childtotoalfinal.toFixed(2));
				$("#orginalprice").val(totalpricefinal.toFixed(2))
				$("#SalsePrice").val(totalpricefinal.toFixed(2))


$("#numberpeople").change(function(){
				var nb=$(this).val();
				$("#chambre").val(nb);
				var unitprix=forfait[0]
				 adulttotalfinal=nb*unitprix.ap;
				totalpricefinal=adulttotalfinal+childtotoalfinal;
				//alert(total);
				$("span.forfait").html("forfait: "+unitprix.ttle+"-")
				$("span.priceadult").html("Adult: "+unitprix.ap+",Total:"+adulttotalfinal.toFixed(2));
				$("#orginalprice").val(totalpricefinal.toFixed(2))
				$("#SalsePrice").val(totalpricefinal.toFixed(2))

			})

// cahange child
$("#nbchild").change(function(){
	
				var nb=$(this).val();
				var unitprix=forfait[0]
				 childtotoalfinal=nb*unitprix.cp;
				totalpricefinal=adulttotalfinal+childtotoalfinal;
				//alert(total);
				$("span.forfait").html("forfait: "+unitprix.ttle+"-")
				$("span.pricechild").html("Child: "+unitprix.cp+",Total:"+childtotoalfinal.toFixed(2));
				$("#orginalprice").val(totalpricefinal.toFixed(2))
				$("#SalsePrice").val(totalpricefinal.toFixed(2))

			})
			
<?php }?>// condition for type ch  egale 0
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
		

//#################################--- with chambre ---##########################################################	
<?php if($infotour[0]["forfaittype"]==1){?>

//initial
	var nb=$("#numberpeople").val();
	$("#chambre").val(nb);
	var unitprix=forfait[nb]
	 adulttotalfinal=nb*unitprix.ap;
	 totalpricefinal=adulttotalfinal+childtotoalfinal;
	//alert(total);
	$("span.forfait").html("forfait: "+unitprix.ttle+"-")
	$("span.priceadult").html("Adult: "+unitprix.ap+",Total:"+adulttotalfinal.toFixed(2));
	$("#orginalprice").val(totalpricefinal.toFixed(2))
	$("#SalsePrice").val(totalpricefinal.toFixed(2))

	
	var nb=$("#nbchild").val();
	if(nb!=0){
	var unitprix=forfait[nb]
	 childtotoalfinal=nb*unitprix.cp;
	$("span.pricechild").html("Child: "+unitprix.cp+",Total:"+childtotoalfinal.toFixed(2));
	}else
	{
		var unitprix=0;
		 childtotoalfinal=0;
		$("span.pricechild").html("Child: "+unitprix.toFixed(2)+",Total:"+childtotoalfinal.toFixed(2));	 
	}
	totalpricefinal=adulttotalfinal+childtotoalfinal;
	//alert(total);
	$("#orginalprice").val(totalpricefinal.toFixed(2))
	$("#SalsePrice").val(totalpricefinal.toFixed(2))

//******** end intial	***********************************************
	
$("#numberpeople").change(function(){
	var nb=$(this).val();
	$("#chambre").val(nb);
	var unitprix=forfait[nb]
	 adulttotalfinal=nb*unitprix.ap;
	 totalpricefinal=adulttotalfinal+childtotoalfinal;
	//alert(total);
	$("span.forfait").html("forfait: "+unitprix.ttle+"-")
	$("span.priceadult").html("Adult: "+unitprix.ap+",Total:"+adulttotalfinal.toFixed(2));
	$("#orginalprice").val(totalpricefinal.toFixed(2))
	$("#SalsePrice").val(totalpricefinal.toFixed(2))

})



// cahange child
$("#nbchild").change(function(){
	
				var nb=$(this).val();
				if(nb!=0){
				var unitprix=forfait[nb]
				 childtotoalfinal=nb*unitprix.cp;
				$("span.pricechild").html("Child: "+unitprix.cp+",Total:"+childtotoalfinal.toFixed(2));
				}else
				{
					var unitprix=0;
					 childtotoalfinal=0;
					$("span.pricechild").html("Child: "+unitprix.toFixed(2)+",Total:"+childtotoalfinal.toFixed(2));	 
				}
				totalpricefinal=adulttotalfinal+childtotoalfinal;
				//alert(total);
				$("span.forfait").html("forfait: "+unitprix.ttle+"-")
				$("#orginalprice").val(totalpricefinal.toFixed(2))
				$("#SalsePrice").val(totalpricefinal.toFixed(2))

			})
	
<?php }?>
//&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&&
		
	})

</script>
</head>

<body>
	
	<div class="principal container_24">
		
		<!--logo-->
		<div class="logo grid_24">
			<div class="grid_1">&nbsp;</div>
			<div class="grid_4 logoimage"><img src="<?php echo $bpath;?>/img/logo.png" height="90"></div>
			<div class="logout grid_5"><a href="index.php?loginprocess/loginout"><img src="<?php echo $bpath;?>/img/bt_logout.jpg"/></a></div>
		</div><!-- end logo-->
		
		<!--menupricipal-->
		<div class="menuprincipal grid_24">
			<div class="menuprincipal grid_23">
			<a class="yearlist " href="index.php?liste/listtour">Back to List </a>
			</div>
		</div>
		<!-- end menupricipal-->
				
			<div class="descprincipal grid_22">
				description
			</div>
			
			<div class="grid_24 listcontent">
				<h1>CLIENT INSCRIPTION</h1>
				<div class="grid_22 list">
<form method="post" action="index.php?add/actionAdd/booking" class="iform grid_18 forminscr" onSubmit="return false" >
<input type="hidden" name="Chambre" id="chambre" value="0">
<input type="hidden" name="orginalprice" id="orginalprice" value="0"/>
<input type="hidden" name="idclient" class="get_idclient" value=0>
<input type="hidden" name="idbus" value="<?php echo $idbus;?>">
<input type="hidden" name="addbookingID" value="<?php echo $addbookingID;?>">

<div id="imessageOK">Thank you! Message Sent!</div>
<div id="imessageERROR">ERROR: Message Not Sent!</div>
<ul>

<li class="iheader">CLIENT INSCRIPTION</li>
<li><label for="Telephone">*Telephone</label><input class="itext nbtel" type="text" name="Telephone" id="Telephone" /><input type="button" class="tel" value="check"></li>
<li><label for="FirstName">*First Name</label><input class="itext" type="text" name="FirstName" id="FirstName" /></li>
<li><label for="LastName">*Last Name</label><input class="itext" type="text" name="LastName" id="LastName" /></li>
<li><label for="Email">*Email</label><input class="itext" type="text" name="Email" id="Email" /></li>
<li><label for="address">Address</label><input class="itext" type="text" name="address" id="address" /></li>
<li><label for="numberpeople">*number people</label>
Adult:<select class="iselect" name="numberpeople" id="numberpeople" style="width:50px;">
<option value="1" selected>1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>
 &nbsp;Child:<select class="iselect" name="nbchild" id="nbchild" style="width:50px;">
<option value="0" selected>0</option>
<option value="1" >1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
</select>



</li>
<li><label for="Language">*Language</label><ul class="langlist"><li><input class="icheckbox" type="checkbox" name="Language" id="Language2" value="French"><label for="Language2" class="ilabel">French</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language3" value="English"><label for="Language3" class="ilabel">English</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language4" value="Spain"><label for="Language4" class="ilabel">Spain</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language5" value="Chinese"><label for="Language5" class="ilabel">Chinese</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language6" value="Japanese"><label for="Language6" class="ilabel">Japanese</label></li>
<li><input class="icheckbox" type="checkbox" name="Language" id="Language7" value="Korean"><label for="Language7" class="ilabel">Korean</label></li>
</ul></li>
<li><label for="Description">*Description</label><textarea class="itextarea" name="Description" id="Description" readonly><?php echo $desc;?></textarea></li>
<li><label for="Chambre">*Salse Price</label><span class="forfait"></span><span class="priceadult"></span>&nbsp;<span class="pricechild"></span><BR/></li>
<li><label for="SalsePrice">*Received:</label>$<input class="itext" type="text" name="SalsePrice" id="SalsePrice"  value="0.00"/></li>

<li><label for="Reminder">*Reminder</label><textarea class="itextarea" name="Reminder" id="Reminder"></textarea></li>
<li><label for="Paid">Paid</label><ul><li>NO<input class="iradio" type="radio" name="Paid" id="Paid2" value="0" checked="checked">&nbsp;&nbsp;YES<input class="iradio" type="radio" name="Paid" id="Paid2" value="1"><label for="Paid2" class="ilabel"></label></li>
</ul></li>
<li><label>&nbsp;</label><input type="submit" class="ibutton sbforminscr"  name="SendaMessage" id="SendaMessage" value="Submit" /></li>
</ul></form>
				</div>
			</div>
		
	</div><!--end principal-->
</body>
</html>